#include "general_task.h"

static int8_t next_prio = APP_TASK_START_PRIO;
static OS_STK app_task_stk[MAX_TASK_CNTS][APP_TASK_STK_SIZE];


int8_t get_next_prio()
{
    next_prio += 1;
    return next_prio - 1;
}

int8_t create_task(void (*task)(void *p_arg), char *task_name)
{
    uint8_t err, task_prio;
    
    task_prio = get_next_prio();
    err = OSTaskCreate(task,
                          0,
                          &app_task_stk[task_prio - APP_TASK_START_PRIO][APP_TASK_STK_SIZE - 1],
                          task_prio);
    if(err != OS_ERR_NONE)
        return err;
    
    OSTaskNameSet(task_prio,  (uint8_t *)task_name, &err);
    return err;
}